# -*-coding: utf-8 -*-
# by zw on 2017/12/25

from bson.objectid import ObjectId


def objectid_to_str(doc):
    """
    :brief mongo的objectid 转换为 字符串
    :param doc:
    :return:
    """
    try:
        doc["_id"] = str(doc["_id"])
    except Exception as e:
        pass


def str_to_objectId(_id):
    """
    :brief 把字符串_id 转换为 ObjectId
    :param _id:
    :return:
    """
    if not _id or not isinstance(_id, str):
        raise ValueError("_id invalid")
    return ObjectId(_id)
